<?php
/*==========================================================================*\
| AGRIVIET - CONTENT MANAGERMENT SYSTEM						
\*==========================================================================*/

	//Xoa nhieu fan tu cung 1 luc
	
	if (isset($_POST['ButDel'])) {
		$cnt=0;
		foreach ($_POST['chk'] as $id)
		{			

				$result = mysql_query("delete from news where id='".$id."'");
				if ($result) {
					$cnt++;		

			}
		}
		echo "<script>window.location='./?act=news</script>";
	}
	
	//Unpub
	if (isset($_POST['Unp'])) {
		$cnt=0;
		foreach ($_POST['chk'] as $id)
		{			

				$result = mysql_query("UPDATE news set published='0' where id='".$id."'");
				if ($result) {
					$cnt++;		

			}
		}
		echo "<script>window.location='./?act=news&code=1</script>";
	}
	
	//Chuyen tin tuc qua danh muc khac
	if (isset($_POST['move'])) {
		$cnt=0;
		foreach ($_POST['chk'] as $id)
		{			

				$result = mysql_query("UPDATE news set catid=".$_POST['catid']." where id='".$id."'");
				if ($result) {
					$cnt++;		
			}
		}
		echo "<script>window.location='./?act=news'</script>";
	}
				
	
		
 if($_GET['code']==1) echo '<div class="blue">Đã cập nhật thành công</div>'; ?>
<form method="POST" name="frmList" action="index.php">
<table border="1" cellpadding="2" style="border-collapse: collapse" bordercolor="#D5E2FF" width="100%" id="AutoNumber1">
  <tr>
    <td height="25" colspan="8" align=left class="xtitle">Danh sách Công Văn </td>
    </tr>
  <tr>
    <td align=center class="title"><input type="checkbox" name="chkall" onclick="chkallClick(this);"></td>
    <td align="center" nowrap class="title"><b>id</b></td>
    <td align=left class="title" >Tiêu đề </td>
    <td align="center" nowrap class="title">Đính kèm </td>
    <td align="center" nowrap class="title">Đến từ </td>
    <td align="center" nowrap class="title">Hiển thị </td>
<!--    <td align="center" nowrap class="title">Hit</td>-->
    <td align="center" nowrap class="title" width="8%">Ngày</td>
    </tr>
<?php
	if($_GET['catid']!='') $where = 'catid='.$_GET['catid'];
	else $where ='1=1';
	/*
	if ($_GET['pub']<>"")
	$sql="select * from news where ($where ) and (published=0) order by title ASC";
	elseif($_GET['new']<>"")
	$sql="select * from news where $where  order by id dESC";
	else 
	
	*/
	$sql="select * from news where $where order by id DESC";
	
	$result=mysql_query($sql);
	$total_records=mysql_num_rows($result);
	$record_per_page=20;
	$scroll=9;
	$page=new Page(); ///creating new instance of Class Page
	$page->set_page_data($urllink,$total_records,$record_per_page,$scroll,true,true,true);
	$page->set_qry_string();
	if($result=mysql_query($page->get_limit_query($sql))){
	$i=0;
	while($row=mysql_fetch_object($result)){
	$i++;
	if ($i%2) $class="le"; else $class="chan";
?>
  <tr class="<?=$class;?>">
    <td align="center">

    <input type="checkbox" name="chk[]" value="<? echo $row->id; ?>"></td>
    <td align="center" class="<?=$class;?>"><? echo $row->id; ?>&nbsp;</td>

    <td align="left" >
	<a href="index.php?act=<?=$_GET['act'];?>_m&id=<? echo $row->id; ?>&catid=<? echo $row->catid; ?>">
	<b><? echo $row->title; ?></b></a></td>

    <td align="center" style="overflow: hidden">

	<?
		if ($row->image<>"")
		{
	  if (strstr($row->image,".pdf"))
	  echo  "<img src=\"../images/pdf.jpg\" border=\"0\" />";
	  else echo  "<img src=\"../images/att.png\" border=\"0\" />";
	  
	  }
	  ?>
	  
	  </td>
    <td align="center" ><?
	$cat = getCat($row->catid,'news_categories');
	echo $cat->title;
	if($cat->title=='') echo "No Category";
	?></td>
    <td align="center" >
	<img src="../images/<? echo $row->published; ?>.png" /></td>
   <!-- <td align="center" ><? echo $row->hit; ?></td>-->
    <td align="center" ><? echo date('d - m - Y',$row->date_add); ?></td>
    </tr>

  <?
	}
}
  ?>
</table>

<input type="hidden" name="act" value="news">

<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table1">
	<tr>
	  <td>

<input type="submit" value="Delete" name="ButDel" onclick="return confirm('B&#7841;n có ch&#7855;c ch&#7855;n mu&#7889;n xoá ?');" class="button">
<input type="submit" value="Unpublish" name="Unp" class="button" />
<!--<input type="submit" value="Empty" name="DelAll" onclick="return confirm('Do you really want to delete all records?');" class="button">-->
<input name="new" type="button" id="new" value="Add new" onclick="window.location='index.php?act=<?=$_GET['act'];?>_m&catid=<?=$_GET['catid'];?>'" class="button" />
<input name="move" type="submit" id="move" value="Move" class="button" />&nbsp;
<input name="button" type="button" class="button" onclick="window.location='./?act=news&amp;catid='+catid.value" value="Filter Cat" />
<select size="1" name="catid">
        <?
		echo "<option value='0'>Root</option>";
		$cats=getListCat();
		foreach ($cats as $cat)
		{
			if ($cat[0]==$catid)
				echo "<option value=".$cat[0]." selected>".$cat[1]."</option>";
			else
				echo "<option value=".$cat[0].">".$cat[1]."</option>";
		}
		?>
      </select></td>
      <td align="right"><div id="pagenav"><?=$page->get_page_nav();?></div></td>
	</tr>
	<tr>
	  <td colspan="2">&nbsp;</td>
    </tr>
</table>
</form>	  